package com.lgh.hotel.controller;

import com.lgh.hotel.common.aop.LogAnnotation;
import com.lgh.hotel.dao.pojo.SysUser;
import com.lgh.hotel.service.SysUserService;
import com.lgh.hotel.vo.Result;
import com.lgh.hotel.vo.SysUserVo;
import com.lgh.hotel.vo.params.PageParams;
import com.lgh.hotel.vo.params.SysUserParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;


@Api(tags = "管理员模块")
@RequestMapping("sysUser")
@RestController
public class SysUserController {

    @Autowired
    SysUserService sysUserService;
    
    @LogAnnotation
    @ApiOperation(value = "获取当前登录的用户信息")
    @GetMapping("/info")
    public Result aest(@RequestHeader("Authorization") String token){
        return Result.succ(sysUserService.findUserByInfoVo(token));
    }

    @LogAnnotation
    @ApiOperation(value = "退出登录")
    @PostMapping("/logout")
    public Result logout(@RequestHeader("Authorization") String token){
        return sysUserService.logoutUser(token);
    }

    @LogAnnotation
    @ApiOperation(value = "获取所有管理员信息")
    @GetMapping("findUserAll")
    public Result findUserAll(){
        return sysUserService.findUserAll();
    }

    @LogAnnotation
    @ApiOperation(value = "获取指定管理员信息")
    @GetMapping("find/user/{type}/{params}")
    public Result findUserBy(@PathVariable("type") String type,@PathVariable("params") String params){
        return sysUserService.findUserBy(type,params);
    }

    @LogAnnotation
    @ApiOperation(value = "分页获取管理员信息")
    @PostMapping("/findUserPage")
    public Result findUserPage(@RequestBody PageParams params){
        return sysUserService.findUserPageList(params);
    }

    @LogAnnotation
    @ApiOperation(value = "增加管理员")
    @PutMapping("/addUser")
    public Result addUser(@RequestBody SysUserParams sysUserParams,@RequestHeader("Authorization")String token){
        return sysUserService.registered(sysUserParams,token);
    }

    @LogAnnotation
    @ApiOperation("更新管理员信息")
    @PutMapping("/updateUser")
    public Result updateUser(@RequestBody SysUser sysUser,@RequestHeader("Authorization")String token){
        return sysUserService.updateUser(sysUser,token);
    }


    @LogAnnotation
    @ApiOperation("删除管理员")
    @DeleteMapping("/deleteUser")
    public Result deleteUser(@RequestBody SysUser sysUser){
        return sysUserService.deleteUser(sysUser.getId());
    }


    @LogAnnotation
    @ApiOperation("获取员工")
    @GetMapping("/findEmployees")
    public Result findEmployees(){
        return sysUserService.findEmployees();
    }

    @LogAnnotation
    @ApiOperation("获取员工分页数据")
    @PostMapping("/findEmployeesPages")
    public Result findEmployeesPages(@RequestBody PageParams params){
        return sysUserService.findEmployeesPages(params);
    }

}
